﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlClient;
using System.Data;

namespace Speedy
{
    public class syncMikroV12 : ISynchronizer
    {
        public string SharEkle(int tip, int cins, int normal_iade, int evrak_tip, DateTime evrak_tarih, string seri, int sira, int satir, string stok_kod, string cari_kod, decimal miktar, string giris_depo, string cikis_depo, int odeme, string plasiyer, string srmerkez, string kullanici, decimal yekun, decimal isk1tutar, decimal isk2tutar, decimal isk3tutar, decimal isk4tutar, decimal isk5tutar, int kdv, string ref_rec, string ref_dbc, decimal fiyat, string belge_no, string firma_no, string sube_no, int adresNo, int tevkifatTipi)
        {
            string sonuc = "";
            try
            {
                using (SqlConnection cn = new SqlConnection(Config.GetConfig.GetValue(CParams.ConStr)))
                {
                    cn.Open();
                    using (SqlCommand cmd = new SqlCommand("TERMINAL_SHAR_EKLE", cn) { CommandType = CommandType.StoredProcedure })
                    {
                        cmd.Parameters.Add("@Tip", SqlDbType.Int).Value = tip;
                        cmd.Parameters.Add("@Cins", SqlDbType.Int).Value = cins;
                        cmd.Parameters.Add("@Normal_iade", SqlDbType.Int).Value = normal_iade;
                        cmd.Parameters.Add("@Evrak_Tip", SqlDbType.Int).Value = evrak_tip;
                        cmd.Parameters.Add("@Evrak_Tarih", SqlDbType.DateTime).Value = new DateTime(evrak_tarih.Year, evrak_tarih.Month, evrak_tarih.Day);
                        cmd.Parameters.Add("@Seri", SqlDbType.VarChar).Value = seri;
                        cmd.Parameters.Add("@Sira", SqlDbType.Int).Value = sira;
                        cmd.Parameters.Add("@Satir", SqlDbType.Int).Value = satir;
                        cmd.Parameters.Add("@Stok_kod", SqlDbType.VarChar).Value = stok_kod;
                        cmd.Parameters.Add("@Cari_kod", SqlDbType.VarChar).Value = cari_kod;
                        cmd.Parameters.Add("@Miktar", SqlDbType.Decimal).Value = miktar;
                        cmd.Parameters.Add("@GirisDepo", SqlDbType.Int).Value = giris_depo;
                        cmd.Parameters.Add("@CikisDepo", SqlDbType.Int).Value = cikis_depo;
                        cmd.Parameters.Add("@odeme", SqlDbType.Int).Value = odeme;
                        cmd.Parameters.Add("@plasiyer", SqlDbType.VarChar).Value = plasiyer;
                        cmd.Parameters.Add("@srmerkez", SqlDbType.VarChar).Value = srmerkez;
                        cmd.Parameters.Add("@kullanici", SqlDbType.VarChar).Value = kullanici;
                        cmd.Parameters.Add("@yekun", SqlDbType.Decimal).Value = yekun;
                        cmd.Parameters.Add("@isk1_tutar", SqlDbType.Decimal).Value = isk1tutar;
                        cmd.Parameters.Add("@isk2_tutar", SqlDbType.Decimal).Value = isk2tutar;
                        cmd.Parameters.Add("@isk3_tutar", SqlDbType.Decimal).Value = isk3tutar;
                        cmd.Parameters.Add("@isk4_tutar", SqlDbType.Decimal).Value = isk4tutar;
                        cmd.Parameters.Add("@isk5_tutar", SqlDbType.Decimal).Value = isk5tutar;
                        cmd.Parameters.Add("@Kdv", SqlDbType.Int).Value = kdv;
                        cmd.Parameters.Add("@Ref_rec", SqlDbType.Int).Value = ref_rec;
                        cmd.Parameters.Add("@Ref_dbc", SqlDbType.Int).Value = ref_dbc;
                        cmd.Parameters.Add("@Fiyat", SqlDbType.Decimal).Value = fiyat;
                        cmd.Parameters.Add("@belge_no", SqlDbType.VarChar, 25).Value = belge_no;
                        cmd.Parameters.Add("@firma_no", SqlDbType.Int).Value = int.Parse(firma_no);
                        cmd.Parameters.Add("@sube_no", SqlDbType.Int).Value = int.Parse(sube_no);
                        cmd.Parameters.Add("@adres_rec", SqlDbType.Int).Value = adresNo;
                        cmd.Parameters.Add("@tevkifat_tip", SqlDbType.TinyInt).Value = tevkifatTipi;
                        cmd.ExecuteNonQuery();
                    }
                    cn.Close();
                }
            }
            catch (Exception ex)
            {
                sonuc = ex.Message;
            }
            return sonuc;
        }
        public string NormalSipEkle(DateTime evrak_tarih, string seri, int sira, int satir, string stok_kod, string cari_kod, decimal miktar, string giris_depo, string cikis_depo, string plasiyer, string srmerkez, string kullanici, decimal yekun, decimal isk1tutar, decimal isk2tutar, decimal isk3tutar, decimal isk4tutar, decimal isk5tutar, int kdv, decimal fiyat, string belge_no, string firma_no, string sube_no)
        {
            string sonuc = "";
            try
            {
                using (SqlConnection cn = new SqlConnection(Config.GetConfig.GetValue(CParams.ConStr)))
                {
                    cn.Open();
                    using (SqlCommand cmd = new SqlCommand("TERMINAL_NORMALSIPARIS_EKLE", cn) { CommandType = CommandType.StoredProcedure })
                    {
                        cmd.Parameters.Add("@Evrak_Tarih", SqlDbType.DateTime).Value = new DateTime(evrak_tarih.Year, evrak_tarih.Month, evrak_tarih.Day);
                        cmd.Parameters.Add("@Seri", SqlDbType.VarChar).Value = seri;
                        cmd.Parameters.Add("@Sira", SqlDbType.Int).Value = sira;
                        cmd.Parameters.Add("@Satir", SqlDbType.Int).Value = satir;
                        cmd.Parameters.Add("@Stok_kod", SqlDbType.VarChar).Value = stok_kod;
                        cmd.Parameters.Add("@Cari_kod", SqlDbType.VarChar).Value = cari_kod;
                        cmd.Parameters.Add("@Miktar", SqlDbType.Decimal).Value = miktar;
                        cmd.Parameters.Add("@GirisDepo", SqlDbType.Int).Value = giris_depo;
                        cmd.Parameters.Add("@CikisDepo", SqlDbType.Int).Value = cikis_depo;
                        cmd.Parameters.Add("@plasiyer", SqlDbType.VarChar).Value = plasiyer;
                        cmd.Parameters.Add("@srmerkez", SqlDbType.VarChar).Value = srmerkez;
                        cmd.Parameters.Add("@kullanici", SqlDbType.VarChar).Value = kullanici;
                        cmd.Parameters.Add("@yekun", SqlDbType.Decimal).Value = yekun;
                        cmd.Parameters.Add("@isk1_tutar", SqlDbType.Decimal).Value = isk1tutar;
                        cmd.Parameters.Add("@isk2_tutar", SqlDbType.Decimal).Value = isk2tutar;
                        cmd.Parameters.Add("@isk3_tutar", SqlDbType.Decimal).Value = isk3tutar;
                        cmd.Parameters.Add("@isk4_tutar", SqlDbType.Decimal).Value = isk4tutar;
                        cmd.Parameters.Add("@isk5_tutar", SqlDbType.Decimal).Value = isk5tutar;
                        cmd.Parameters.Add("@Kdv", SqlDbType.Int).Value = kdv;
                        cmd.Parameters.Add("@Fiyat", SqlDbType.Decimal).Value = fiyat;
                        cmd.Parameters.Add("@belge_no", SqlDbType.VarChar, 25).Value = belge_no;
                        cmd.Parameters.Add("@firma_no", SqlDbType.Int).Value = int.Parse(firma_no);
                        cmd.Parameters.Add("@sube_no", SqlDbType.Int).Value = int.Parse(sube_no);
                        cmd.ExecuteNonQuery();
                    }
                    cn.Close();
                }
            }
            catch (Exception ex)
            {
                sonuc = ex.Message;
            }
            return sonuc;
        }
        public string AlinanSipEkle(DateTime evrak_tarih, string seri, int sira, int satir, string stok_kod, string cari_kod, decimal miktar, string giris_depo, string cikis_depo, string plasiyer, string srmerkez, string kullanici, decimal yekun, decimal isk1tutar, decimal isk2tutar, decimal isk3tutar, decimal isk4tutar, decimal isk5tutar, int kdv, decimal fiyat, string belge_no, string firma_no, string sube_no, int dovizCinsi, decimal dovizKur)
        {
            string sonuc = "";
            try
            {
                using (SqlConnection cn = new SqlConnection(Config.GetConfig.GetValue(CParams.ConStr)))
                {
                    cn.Open();
                    using (SqlCommand cmd = new SqlCommand("TERMINAL_ALINANSIPARIS_EKLE", cn) { CommandType = CommandType.StoredProcedure })
                    {
                        cmd.Parameters.Add("@Evrak_Tarih", SqlDbType.DateTime).Value = new DateTime(evrak_tarih.Year, evrak_tarih.Month, evrak_tarih.Day);
                        cmd.Parameters.Add("@Seri", SqlDbType.VarChar).Value = seri;
                        cmd.Parameters.Add("@Sira", SqlDbType.Int).Value = sira;
                        cmd.Parameters.Add("@Satir", SqlDbType.Int).Value = satir;
                        cmd.Parameters.Add("@Stok_kod", SqlDbType.VarChar).Value = stok_kod;
                        cmd.Parameters.Add("@Cari_kod", SqlDbType.VarChar).Value = cari_kod;
                        cmd.Parameters.Add("@Miktar", SqlDbType.Decimal).Value = miktar;
                        cmd.Parameters.Add("@GirisDepo", SqlDbType.Int).Value = giris_depo;
                        cmd.Parameters.Add("@CikisDepo", SqlDbType.Int).Value = cikis_depo;
                        cmd.Parameters.Add("@plasiyer", SqlDbType.VarChar).Value = plasiyer;
                        cmd.Parameters.Add("@srmerkez", SqlDbType.VarChar).Value = srmerkez;
                        cmd.Parameters.Add("@kullanici", SqlDbType.VarChar).Value = kullanici;
                        cmd.Parameters.Add("@yekun", SqlDbType.Decimal).Value = yekun;
                        cmd.Parameters.Add("@isk1_tutar", SqlDbType.Decimal).Value = isk1tutar;
                        cmd.Parameters.Add("@isk2_tutar", SqlDbType.Decimal).Value = isk2tutar;
                        cmd.Parameters.Add("@isk3_tutar", SqlDbType.Decimal).Value = isk3tutar;
                        cmd.Parameters.Add("@isk4_tutar", SqlDbType.Decimal).Value = isk4tutar;
                        cmd.Parameters.Add("@isk5_tutar", SqlDbType.Decimal).Value = isk5tutar;
                        cmd.Parameters.Add("@Kdv", SqlDbType.Int).Value = kdv;
                        cmd.Parameters.Add("@Fiyat", SqlDbType.Decimal).Value = fiyat;
                        cmd.Parameters.Add("@belge_no", SqlDbType.VarChar, 25).Value = belge_no;
                        cmd.Parameters.Add("@firma_no", SqlDbType.Int).Value = int.Parse(firma_no);
                        cmd.Parameters.Add("@sube_no", SqlDbType.Int).Value = int.Parse(sube_no);
                        cmd.Parameters.Add("@doviz_cinsi", SqlDbType.Int).Value = dovizCinsi;
                        cmd.Parameters.Add("@doviz_kur", SqlDbType.Float).Value = dovizKur;
                        cmd.ExecuteNonQuery();
                    }
                    cn.Close();
                }
            }
            catch (Exception ex)
            {
                sonuc = ex.Message;
            }
            return sonuc;
        }
        public string ProformaSipEkle(int tip, int cins, int normal_iade, int evrak_tip, DateTime evrak_tarih, string seri, int sira, int satir, string stok_kod, string cari_kod, decimal miktar, string giris_depo, string cikis_depo, string plasiyer, string srmerkez, string kullanici, decimal yekun, decimal isk1tutar, decimal isk2tutar, decimal isk3tutar, decimal isk4tutar, decimal isk5tutar, int kdv, decimal fiyat, string belge_no, string firma_no, string sube_no)
        {
            string sonuc = "";
            try
            {
                using (SqlConnection cn = new SqlConnection(Config.GetConfig.GetValue(CParams.ConStr)))
                {
                    cn.Open();
                    using (SqlCommand cmd = new SqlCommand("TERMINAL_PROFORMA_SIPARISLER_EKLE", cn) { CommandType = CommandType.StoredProcedure })
                    {
                        cmd.Parameters.Add("@Tip", SqlDbType.Int).Value = tip;
                        cmd.Parameters.Add("@Cins", SqlDbType.Int).Value = cins;
                        cmd.Parameters.Add("@Normal_iade", SqlDbType.Int).Value = normal_iade;
                        cmd.Parameters.Add("@Evrak_Tip", SqlDbType.Int).Value = evrak_tip;
                        cmd.Parameters.Add("@Evrak_Tarih", SqlDbType.DateTime).Value = new DateTime(evrak_tarih.Year, evrak_tarih.Month, evrak_tarih.Day);
                        cmd.Parameters.Add("@Seri", SqlDbType.VarChar).Value = seri;
                        cmd.Parameters.Add("@Sira", SqlDbType.Int).Value = sira;
                        cmd.Parameters.Add("@Satir", SqlDbType.Int).Value = satir;
                        cmd.Parameters.Add("@Stok_kod", SqlDbType.VarChar).Value = stok_kod;
                        cmd.Parameters.Add("@Cari_kod", SqlDbType.VarChar).Value = cari_kod;
                        cmd.Parameters.Add("@Miktar", SqlDbType.Decimal).Value = miktar;
                        cmd.Parameters.Add("@GirisDepo", SqlDbType.Int).Value = giris_depo;
                        cmd.Parameters.Add("@CikisDepo", SqlDbType.Int).Value = cikis_depo;
                        cmd.Parameters.Add("@plasiyer", SqlDbType.VarChar).Value = plasiyer;
                        cmd.Parameters.Add("@srmerkez", SqlDbType.VarChar).Value = srmerkez;
                        cmd.Parameters.Add("@kullanici", SqlDbType.VarChar).Value = kullanici;
                        cmd.Parameters.Add("@yekun", SqlDbType.Decimal).Value = yekun;
                        cmd.Parameters.Add("@isk1_tutar", SqlDbType.Decimal).Value = isk1tutar;
                        cmd.Parameters.Add("@isk2_tutar", SqlDbType.Decimal).Value = isk2tutar;
                        cmd.Parameters.Add("@isk3_tutar", SqlDbType.Decimal).Value = isk3tutar;
                        cmd.Parameters.Add("@isk4_tutar", SqlDbType.Decimal).Value = isk4tutar;
                        cmd.Parameters.Add("@isk5_tutar", SqlDbType.Decimal).Value = isk5tutar;
                        cmd.Parameters.Add("@Kdv", SqlDbType.Int).Value = kdv;
                        cmd.Parameters.Add("@Fiyat", SqlDbType.Decimal).Value = fiyat;
                        cmd.Parameters.Add("@belge_no", SqlDbType.VarChar, 25).Value = belge_no;
                        cmd.Parameters.Add("@firma_no", SqlDbType.Int).Value = int.Parse(firma_no);
                        cmd.Parameters.Add("@sube_no", SqlDbType.Int).Value = int.Parse(sube_no);
                        cmd.ExecuteNonQuery();
                    }
                    cn.Close();
                }
            }
            catch (Exception ex)
            {
                sonuc = ex.Message;
            }
            return sonuc;
        }
        public string SubeSipEkle(int tip, int cins, int normal_iade, int evrak_tip, DateTime evrak_tarih, string seri, int sira, int satir, string stok_kod, string cari_kod, decimal miktar, string giris_depo, string cikis_depo, string plasiyer, string srmerkez, string kullanici, decimal yekun, decimal isk1tutar, decimal isk2tutar, decimal isk3tutar, decimal isk4tutar, decimal isk5tutar, int kdv, decimal fiyat, string belge_no, string firma_no, string sube_no)
        {
            string sonuc = "";
            try
            {
                using (SqlConnection cn = new SqlConnection(Config.GetConfig.GetValue(CParams.ConStr)))
                {
                    cn.Open();
                    using (SqlCommand cmd = new SqlCommand("TERMINAL_SUBE_SIPARIS_EKLE", cn) { CommandType = CommandType.StoredProcedure })
                    {
                        cmd.Parameters.Add("@Tip", SqlDbType.Int).Value = tip;
                        cmd.Parameters.Add("@Cins", SqlDbType.Int).Value = cins;
                        cmd.Parameters.Add("@Normal_iade", SqlDbType.Int).Value = normal_iade;
                        cmd.Parameters.Add("@Evrak_Tip", SqlDbType.Int).Value = evrak_tip;
                        cmd.Parameters.Add("@Evrak_Tarih", SqlDbType.DateTime).Value = new DateTime(evrak_tarih.Year, evrak_tarih.Month, evrak_tarih.Day);
                        cmd.Parameters.Add("@Seri", SqlDbType.VarChar).Value = seri;
                        cmd.Parameters.Add("@Sira", SqlDbType.Int).Value = sira;
                        cmd.Parameters.Add("@Satir", SqlDbType.Int).Value = satir;
                        cmd.Parameters.Add("@Stok_kod", SqlDbType.VarChar).Value = stok_kod;
                        cmd.Parameters.Add("@Cari_kod", SqlDbType.VarChar).Value = cari_kod;
                        cmd.Parameters.Add("@Miktar", SqlDbType.Decimal).Value = miktar;
                        cmd.Parameters.Add("@GirisDepo", SqlDbType.Int).Value = giris_depo;
                        cmd.Parameters.Add("@CikisDepo", SqlDbType.Int).Value = cikis_depo;
                        cmd.Parameters.Add("@plasiyer", SqlDbType.VarChar).Value = plasiyer;
                        cmd.Parameters.Add("@srmerkez", SqlDbType.VarChar).Value = srmerkez;
                        cmd.Parameters.Add("@kullanici", SqlDbType.VarChar).Value = kullanici;
                        cmd.Parameters.Add("@yekun", SqlDbType.Decimal).Value = yekun;
                        cmd.Parameters.Add("@isk1_tutar", SqlDbType.Decimal).Value = isk1tutar;
                        cmd.Parameters.Add("@isk2_tutar", SqlDbType.Decimal).Value = isk2tutar;
                        cmd.Parameters.Add("@isk3_tutar", SqlDbType.Decimal).Value = isk3tutar;
                        cmd.Parameters.Add("@isk4_tutar", SqlDbType.Decimal).Value = isk4tutar;
                        cmd.Parameters.Add("@isk5_tutar", SqlDbType.Decimal).Value = isk5tutar;
                        cmd.Parameters.Add("@Kdv", SqlDbType.Int).Value = kdv;
                        cmd.Parameters.Add("@Fiyat", SqlDbType.Decimal).Value = fiyat;
                        cmd.Parameters.Add("@belge_no", SqlDbType.VarChar, 25).Value = belge_no;
                        cmd.Parameters.Add("@firma_no", SqlDbType.Int).Value = int.Parse(firma_no);
                        cmd.Parameters.Add("@sube_no", SqlDbType.Int).Value = int.Parse(sube_no);
                        cmd.ExecuteNonQuery();
                    }
                    cn.Close();
                }
            }
            catch (Exception ex)
            {
                sonuc = ex.Message;
            }
            return sonuc;
        }
        public string CariHarKaydet(int tip, int cins, bool normal_iade, int evrak_tip, string seri, int sira, DateTime tarih, string belge_no, string carikod, decimal aratoplam, decimal meblag, decimal isk1, decimal isk2, decimal isk3, decimal isk4, decimal isk5, decimal isk6, decimal vergi1, decimal vergi2, decimal vergi3, decimal vergi4, decimal vergi5, decimal vergi6, string firma_no, string sube_no, int vade, string srmKod, string depoKod, string plasiyerKod, string kasaKodu, string aciklama, bool yazdirildi, Dictionary<string, decimal> tevkifatTutari)
        {
            using (SqlConnection cn = new SqlConnection(Config.GetConfig.GetValue(CParams.ConStr)))
            {
                using (SqlCommand cmd = new SqlCommand("TERMINAL_CHAR_EKLE", cn) { CommandType = CommandType.StoredProcedure })
                {
                    cmd.Parameters.Add("@cha_RECid_DBCno", SqlDbType.SmallInt).Value = 0;
                    cmd.Parameters.Add("@cha_RECid_RECno", SqlDbType.Int).Value = -1;
                    cmd.Parameters.Add("@cha_SpecRecNo", SqlDbType.Int).Value = 0;
                    cmd.Parameters.Add("@cha_iptal", SqlDbType.Bit).Value = 0;
                    cmd.Parameters.Add("@cha_fileid", SqlDbType.SmallInt).Value = 51;
                    cmd.Parameters.Add("@cha_hidden", SqlDbType.Bit).Value = 0;
                    cmd.Parameters.Add("@cha_kilitli", SqlDbType.Bit).Value = 0;
                    cmd.Parameters.Add("@cha_degisti", SqlDbType.Bit).Value = 0;
                    cmd.Parameters.Add("@cha_CheckSum", SqlDbType.Int).Value = 0;
                    cmd.Parameters.Add("@cha_create_user", SqlDbType.SmallInt).Value = 1;
                    cmd.Parameters.Add("@cha_create_date", SqlDbType.DateTime).Value = DateTime.Now;
                    cmd.Parameters.Add("@cha_lastup_user", SqlDbType.SmallInt).Value = 1;
                    cmd.Parameters.Add("@cha_lastup_date", SqlDbType.DateTime).Value = DateTime.Now;
                    cmd.Parameters.Add("@cha_special1", SqlDbType.VarChar).Value = "";
                    cmd.Parameters.Add("@cha_special2", SqlDbType.VarChar).Value = "";
                    cmd.Parameters.Add("@cha_special3", SqlDbType.VarChar).Value = "";
                    cmd.Parameters.Add("@cha_firmano", SqlDbType.Int).Value = int.Parse(firma_no);
                    cmd.Parameters.Add("@cha_subeno", SqlDbType.Int).Value = int.Parse(sube_no);
                    cmd.Parameters.Add("@cha_tarihi", SqlDbType.DateTime).Value = tarih;
                    cmd.Parameters.Add("@cha_tip", SqlDbType.TinyInt).Value = tip;
                    cmd.Parameters.Add("@cha_cinsi", SqlDbType.TinyInt).Value = cins;
                    cmd.Parameters.Add("@cha_normal_Iade", SqlDbType.TinyInt).Value = normal_iade;
                    cmd.Parameters.Add("@cha_evrak_tip", SqlDbType.TinyInt).Value = evrak_tip;
                    cmd.Parameters.Add("@cha_satir_no", SqlDbType.Int).Value = 0;
                    cmd.Parameters.Add("@cha_evrakno_seri", SqlDbType.VarChar).Value = seri;
                    cmd.Parameters.Add("@cha_evrakno_sira", SqlDbType.Int).Value = sira;
                    cmd.Parameters.Add("@cha_belge_no", SqlDbType.VarChar).Value = belge_no;
                    cmd.Parameters.Add("@cha_belge_tarih", SqlDbType.DateTime).Value = new DateTime(tarih.Year, tarih.Month, tarih.Day);
                    cmd.Parameters.Add("@cha_cari_cins", SqlDbType.TinyInt).Value = 0;
                    cmd.Parameters.Add("@cha_kod", SqlDbType.VarChar).Value = carikod;
                    cmd.Parameters.Add("@cha_kasa_hizmet", SqlDbType.TinyInt).Value = 0;
                    cmd.Parameters.Add("@cha_kasa_hizkod", SqlDbType.VarChar).Value = "";
                    cmd.Parameters.Add("@cha_d_kurtar", SqlDbType.DateTime).Value = "1899-12-30 00:00:00";
                    cmd.Parameters.Add("@cha_d_cins", SqlDbType.TinyInt).Value = 0;
                    cmd.Parameters.Add("@cha_d_kur", SqlDbType.Float).Value = 1;
                    cmd.Parameters.Add("@cha_altd_kur", SqlDbType.Float).Value = 1;
                    cmd.Parameters.Add("@cha_grupno", SqlDbType.TinyInt).Value = 0;
                    cmd.Parameters.Add("@cha_meblag", SqlDbType.Float).Value = meblag;
                    cmd.Parameters.Add("@cha_vade", SqlDbType.Int).Value = vade;
                    cmd.Parameters.Add("@cha_fis_tarih", SqlDbType.DateTime).Value = "1899-12-30 00:00:00";
                    cmd.Parameters.Add("@cha_fis_sirano", SqlDbType.Int).Value = 0;
                    cmd.Parameters.Add("@cha_ft_iskonto1", SqlDbType.Float).Value = isk1;
                    cmd.Parameters.Add("@cha_ft_iskonto2", SqlDbType.Float).Value = isk2;
                    cmd.Parameters.Add("@cha_ft_iskonto3", SqlDbType.Float).Value = isk3;
                    cmd.Parameters.Add("@cha_ft_iskonto4", SqlDbType.Float).Value = isk4;
                    cmd.Parameters.Add("@cha_ft_iskonto5", SqlDbType.Float).Value = isk5;
                    cmd.Parameters.Add("@cha_ft_iskonto6", SqlDbType.Float).Value = isk6;
                    cmd.Parameters.Add("@cha_ft_masraf1", SqlDbType.Float).Value = 0;
                    cmd.Parameters.Add("@cha_ft_masraf2", SqlDbType.Float).Value = 0;
                    cmd.Parameters.Add("@cha_ft_masraf3", SqlDbType.Float).Value = 0;
                    cmd.Parameters.Add("@cha_ft_masraf4", SqlDbType.Float).Value = 0;
                    cmd.Parameters.Add("@cha_vergi1", SqlDbType.Float).Value = vergi2;
                    cmd.Parameters.Add("@cha_vergi2", SqlDbType.Float).Value = vergi3;
                    cmd.Parameters.Add("@cha_vergi3", SqlDbType.Float).Value = vergi4;
                    cmd.Parameters.Add("@cha_vergi4", SqlDbType.Float).Value = vergi5;
                    cmd.Parameters.Add("@cha_vergi5", SqlDbType.Float).Value = vergi6;
                    cmd.Parameters.Add("@cha_vergi6", SqlDbType.Float).Value = 0;
                    cmd.Parameters.Add("@cha_vergi7", SqlDbType.Float).Value = 0;
                    cmd.Parameters.Add("@cha_vergi8", SqlDbType.Float).Value = 0;
                    cmd.Parameters.Add("@cha_vergi9", SqlDbType.Float).Value = 0;
                    cmd.Parameters.Add("@cha_vergi10", SqlDbType.Float).Value = 0;
                    cmd.Parameters.Add("@cha_yuvarlama", SqlDbType.Float).Value = 0;
                    cmd.Parameters.Add("@cha_tpoz", SqlDbType.TinyInt).Value = 0;
                    cmd.Parameters.Add("@cha_aciklama", SqlDbType.VarChar).Value = aciklama;
                    cmd.Parameters.Add("@cha_trefno", SqlDbType.VarChar).Value = "";
                    cmd.Parameters.Add("@cha_sntck_poz", SqlDbType.TinyInt).Value = 0;
                    cmd.Parameters.Add("@cha_karsidcinsi", SqlDbType.TinyInt).Value = 0;
                    cmd.Parameters.Add("@cha_karsid_kur", SqlDbType.Float).Value = 1;
                    cmd.Parameters.Add("@cha_karsidgrupno", SqlDbType.TinyInt).Value = 0;
                    cmd.Parameters.Add("@cha_srmrkkodu", SqlDbType.VarChar).Value = srmKod;
                    cmd.Parameters.Add("@cha_reftarihi", SqlDbType.DateTime).Value = "1899-12-30 00:00:00";
                    cmd.Parameters.Add("@cha_odeme_arr1", SqlDbType.Float).Value = 0;
                    cmd.Parameters.Add("@cha_odeme_arr2", SqlDbType.Float).Value = 0;
                    cmd.Parameters.Add("@cha_odeme_arr3", SqlDbType.Float).Value = 0;
                    cmd.Parameters.Add("@cha_odeme_arr4", SqlDbType.Float).Value = 0;
                    cmd.Parameters.Add("@cha_odeme_arr5", SqlDbType.Float).Value = 0;
                    cmd.Parameters.Add("@cha_odeme_arr6", SqlDbType.Float).Value = 0;
                    cmd.Parameters.Add("@cha_odeme_arr7", SqlDbType.Float).Value = 0;
                    cmd.Parameters.Add("@cha_odeme_arr8", SqlDbType.Float).Value = 0;
                    cmd.Parameters.Add("@cha_miktari", SqlDbType.Float).Value = 0;
                    cmd.Parameters.Add("@cha_aratoplam", SqlDbType.Float).Value = aratoplam;
                    cmd.Parameters.Add("@cha_vergipntr", SqlDbType.TinyInt).Value = 0;
                    cmd.Parameters.Add("@cha_istisnakodu", SqlDbType.TinyInt).Value = 0;
                    cmd.Parameters.Add("@cha_ver_tev_carpani", SqlDbType.Float).Value = 0;
                    cmd.Parameters.Add("@cha_stopaj", SqlDbType.Float).Value = 0;
                    cmd.Parameters.Add("@cha_savsandesfonu", SqlDbType.Float).Value = 0;
                    cmd.Parameters.Add("@cha_vergisiz_fl", SqlDbType.Bit).Value = 0;
                    cmd.Parameters.Add("@cha_satici_kodu", SqlDbType.VarChar).Value = plasiyerKod;
                    cmd.Parameters.Add("@cha_mustahsil_borsa", SqlDbType.Float).Value = 0;
                    cmd.Parameters.Add("@cha_mustahsil_bagkur", SqlDbType.Float).Value = 0;
                    cmd.Parameters.Add("@cha_mustahsil_diger", SqlDbType.Float).Value = 0;
                    cmd.Parameters.Add("@cha_HalMSDF", SqlDbType.Float).Value = 0;
                    cmd.Parameters.Add("@cha_HalHamaliye", SqlDbType.Float).Value = 0;
                    cmd.Parameters.Add("@cha_HalStopaj", SqlDbType.Float).Value = 0;
                    cmd.Parameters.Add("@cha_HalKomisyonu", SqlDbType.Float).Value = 0;
                    cmd.Parameters.Add("@cha_StFonPntr", SqlDbType.TinyInt).Value = 0;
                    cmd.Parameters.Add("@cha_pos_hareketi", SqlDbType.Bit).Value = 0;
                    cmd.Parameters.Add("@cha_vardiya_tarihi", SqlDbType.DateTime).Value = "1899-12-30 00:00:00";
                    cmd.Parameters.Add("@cha_vardiya_no", SqlDbType.TinyInt).Value = 0;
                    cmd.Parameters.Add("@cha_vardiya_evrak_ti", SqlDbType.TinyInt).Value = 0;
                    cmd.Parameters.Add("@cha_HalRusum", SqlDbType.Float).Value = 0;
                    cmd.Parameters.Add("@cha_HalNavlunTut", SqlDbType.Float).Value = 0;
                    cmd.Parameters.Add("@cha_HalRehinFuture", SqlDbType.Float).Value = 0;
                    cmd.Parameters.Add("@cha_HalKomisyon", SqlDbType.Float).Value = 0;
                    cmd.Parameters.Add("@cha_Vade_Farki_Yuz", SqlDbType.Float).Value = 0;
                    cmd.Parameters.Add("@cha_karsisrmrkkodu", SqlDbType.VarChar).Value = "";
                    cmd.Parameters.Add("@cha_EXIMkodu", SqlDbType.VarChar).Value = "";
                    cmd.Parameters.Add("@cha_HalRehinSandikmiktari", SqlDbType.Float).Value = 0;
                    cmd.Parameters.Add("@cha_HalSandikVrMiktar", SqlDbType.Float).Value = 0;
                    cmd.Parameters.Add("@cha_HalSandikTutari", SqlDbType.Float).Value = 0;
                    cmd.Parameters.Add("@cha_HalSandikKDVTutari", SqlDbType.Float).Value = 0;
                    cmd.Parameters.Add("@cha_HalrehinSandikTutari", SqlDbType.Float).Value = 0;
                    cmd.Parameters.Add("@cha_Tevkifat_turu", SqlDbType.TinyInt).Value = 0;
                    cmd.Parameters.Add("@cha_ticaret_turu", SqlDbType.TinyInt).Value = 0;
                    cmd.Parameters.Add("@cha_otvtutari", SqlDbType.Float).Value = 0;
                    cmd.Parameters.Add("@cha_otvvergisiz_fl", SqlDbType.Bit).Value = 0;
                    cmd.Parameters.Add("@cha_projekodu", SqlDbType.VarChar).Value = "";
                    cmd.Parameters.Add("@cha_sozlesme_DBCno", SqlDbType.SmallInt).Value = 0;
                    cmd.Parameters.Add("@cha_sozlesme_RECno", SqlDbType.Int).Value = 0;
                    cmd.Parameters.Add("@cha_yat_tes_kodu", SqlDbType.VarChar).Value = "";
                    cmd.Parameters.Add("@cha_ciro_cari_kodu", SqlDbType.VarChar).Value = 01;
                    cmd.Parameters.Add("@cha_oivergisiz_fl", SqlDbType.Bit).Value = 0;
                    cmd.Parameters.Add("@cha_meblag_ana_doviz_icin_gecersiz_fl", SqlDbType.TinyInt).Value = 0;
                    cmd.Parameters.Add("@cha_meblag_alt_doviz_icin_gecersiz_fl", SqlDbType.TinyInt).Value = 0;
                    cmd.Parameters.Add("@cha_meblag_orj_doviz_icin_gecersiz_fl", SqlDbType.TinyInt).Value = 0;
                    cmd.Parameters.Add("@cha_ciroprim_DBCno", SqlDbType.SmallInt).Value = 0;
                    cmd.Parameters.Add("@cha_ciroprim_RECno", SqlDbType.Int).Value = 0;
                    cmd.Parameters.Add("@cha_HalHamaliyeKdv", SqlDbType.Float).Value = 0;
                    cmd.Parameters.Add("@cha_HalHamaliyeVergisiz_fl", SqlDbType.Bit).Value = 0;
                    cn.Open();
                    try
                    {
                        cmd.ExecuteNonQuery();
                        TevkifatGuncelle(evrak_tip, seri, sira, tevkifatTutari);
                    }
                    catch (Exception ex)
                    {
                        Logging.GetLog.ErrorLog(ex);
                    }

                }
                cn.Close();
            }
            return "";
        }
        public string TahsilatEkle(TahsilatTipi tahsilatTipi, DateTime tarih, string seri, int sira, int satir, string belgeNo, string cariKodu, string kasaHizKod, decimal meblag, string refNo, string srmMerkez, DateTime vade, string bankaAdi, string subeAdi, string hesapNo, string kesideYeri, string kartNo, string cekNo, string depoKod, string plasiyerKod)
        {
            #region Evrak Tip Cins
            int tip = 1;
            int cins = 0;
            int normIade = 0;
            int evrTip = 1;
            int hizTip = 4;
            int senetcekPoz = 0;
            int karsidgrupno = 0;
            int vadeGun = int.Parse(vade.Year.ToString() + vade.Month.ToString("00") + vade.Day.ToString("00"));

            switch (tahsilatTipi)
            {
                case TahsilatTipi.Nakit:
                    tip = 1;
                    cins = 0;
                    normIade = 0;
                    evrTip = 1;
                    hizTip = 4;
                    break;
                case TahsilatTipi.Cek:
                    tip = 1;
                    cins = 1;
                    normIade = 0;
                    evrTip = 1;
                    hizTip = 4;
                    break;
                case TahsilatTipi.Senet:
                    tip = 1;
                    cins = 2;
                    normIade = 0;
                    evrTip = 1;
                    hizTip = 4;
                    break;
                case TahsilatTipi.KrediKarti:
                    tip = 1;
                    cins = 19;
                    normIade = 0;
                    evrTip = 1;
                    hizTip = 2;
                    senetcekPoz = 2;
                    karsidgrupno = 7;
                    kasaHizKod = bankaAdi;
                    vade = vade.AddDays(BankaTahsilSuresi(bankaAdi));
                    vadeGun = int.Parse(vade.Year.ToString() + vade.Month.ToString("00") + vade.Day.ToString("00"));
                    break;
                case TahsilatTipi.Havale:
                    tip = 1;
                    cins = 17;
                    normIade = 0;
                    evrTip = 1;
                    hizTip = 2;
                    senetcekPoz = 2;
                    karsidgrupno = 9;
                    break;
            }
            #endregion

            string sql = "insert into CARI_HESAP_HAREKETLERI (cha_RECid_DBCno,cha_RECid_RECno,cha_SpecRecNo,cha_iptal,cha_fileid,cha_hidden,cha_kilitli,cha_degisti,cha_CheckSum,cha_create_user,cha_create_date,cha_lastup_user,cha_lastup_date,cha_special1,cha_special2,cha_special3,cha_firmano,cha_subeno,cha_tarihi,cha_tip,cha_cinsi,cha_normal_Iade,cha_evrak_tip,cha_satir_no,cha_evrakno_seri,cha_evrakno_sira,cha_belge_no,cha_belge_tarih,cha_cari_cins,cha_kod,cha_kasa_hizmet,cha_kasa_hizkod,cha_d_kurtar,cha_d_cins,cha_d_kur,cha_altd_kur,cha_grupno,cha_meblag,cha_vade,cha_fis_tarih,cha_fis_sirano,cha_ft_iskonto1,cha_ft_iskonto2,cha_ft_iskonto3,cha_ft_iskonto4,cha_ft_iskonto5,cha_ft_iskonto6,cha_ft_masraf1,cha_ft_masraf2,cha_ft_masraf3,cha_ft_masraf4,cha_vergi1,cha_vergi2,cha_vergi3,cha_vergi4,cha_vergi5,cha_vergi6,cha_vergi7,cha_vergi8,cha_vergi9,cha_vergi10,cha_yuvarlama,cha_tpoz,cha_aciklama,cha_trefno,cha_sntck_poz,cha_karsidcinsi,cha_karsid_kur,cha_karsidgrupno,cha_srmrkkodu,cha_reftarihi,cha_odeme_arr1,cha_odeme_arr2,cha_odeme_arr3,cha_odeme_arr4,cha_odeme_arr5,cha_odeme_arr6,cha_odeme_arr7,cha_odeme_arr8,cha_miktari,cha_aratoplam,cha_vergipntr,cha_istisnakodu,cha_ver_tev_carpani,cha_stopaj,cha_savsandesfonu,cha_vergisiz_fl,cha_satici_kodu,cha_mustahsil_borsa,cha_mustahsil_bagkur,cha_mustahsil_diger,cha_HalMSDF,cha_HalHamaliye,cha_HalStopaj,cha_HalKomisyonu,cha_StFonPntr,cha_pos_hareketi,cha_vardiya_tarihi,cha_vardiya_no,cha_vardiya_evrak_ti,cha_HalRusum,cha_HalNavlunTut,cha_HalRehinFuture,cha_HalKomisyon,cha_Vade_Farki_Yuz,cha_karsisrmrkkodu,cha_EXIMkodu,cha_HalRehinSandikmiktari,cha_HalSandikVrMiktar,cha_HalSandikTutari,cha_HalSandikKDVTutari,cha_HalrehinSandikTutari,cha_Tevkifat_turu,cha_ticaret_turu,cha_otvtutari,cha_otvvergisiz_fl,cha_projekodu,cha_sozlesme_DBCno,cha_sozlesme_RECno,cha_yat_tes_kodu,cha_ciro_cari_kodu,cha_oivergisiz_fl,cha_meblag_ana_doviz_icin_gecersiz_fl,cha_meblag_alt_doviz_icin_gecersiz_fl,cha_meblag_orj_doviz_icin_gecersiz_fl,cha_ciroprim_DBCno,cha_ciroprim_RECno,cha_HalHamaliyeKdv,cha_HalHamaliyeVergisiz_fl) values (@cha_RECid_DBCno,@cha_RECid_RECno,@cha_SpecRecNo,@cha_iptal,@cha_fileid,@cha_hidden,@cha_kilitli,@cha_degisti,@cha_CheckSum,@cha_create_user,@cha_create_date,@cha_lastup_user,@cha_lastup_date,@cha_special1,@cha_special2,@cha_special3,@cha_firmano,@cha_subeno,@cha_tarihi,@cha_tip,@cha_cinsi,@cha_normal_Iade,@cha_evrak_tip,@cha_satir_no,@cha_evrakno_seri,@cha_evrakno_sira,@cha_belge_no,@cha_belge_tarih,@cha_cari_cins,@cha_kod,@cha_kasa_hizmet,@cha_kasa_hizkod,@cha_d_kurtar,@cha_d_cins,@cha_d_kur,@cha_altd_kur,@cha_grupno,@cha_meblag,@cha_vade,@cha_fis_tarih,@cha_fis_sirano,@cha_ft_iskonto1,@cha_ft_iskonto2,@cha_ft_iskonto3,@cha_ft_iskonto4,@cha_ft_iskonto5,@cha_ft_iskonto6,@cha_ft_masraf1,@cha_ft_masraf2,@cha_ft_masraf3,@cha_ft_masraf4,@cha_vergi1,@cha_vergi2,@cha_vergi3,@cha_vergi4,@cha_vergi5,@cha_vergi6,@cha_vergi7,@cha_vergi8,@cha_vergi9,@cha_vergi10,@cha_yuvarlama,@cha_tpoz,@cha_aciklama,@cha_trefno,@cha_sntck_poz,@cha_karsidcinsi,@cha_karsid_kur,@cha_karsidgrupno,@cha_srmrkkodu,@cha_reftarihi,@cha_odeme_arr1,@cha_odeme_arr2,@cha_odeme_arr3,@cha_odeme_arr4,@cha_odeme_arr5,@cha_odeme_arr6,@cha_odeme_arr7,@cha_odeme_arr8,@cha_miktari,@cha_aratoplam,@cha_vergipntr,@cha_istisnakodu,@cha_ver_tev_carpani,@cha_stopaj,@cha_savsandesfonu,@cha_vergisiz_fl,@cha_satici_kodu,@cha_mustahsil_borsa,@cha_mustahsil_bagkur,@cha_mustahsil_diger,@cha_HalMSDF,@cha_HalHamaliye,@cha_HalStopaj,@cha_HalKomisyonu,@cha_StFonPntr,@cha_pos_hareketi,@cha_vardiya_tarihi,@cha_vardiya_no,@cha_vardiya_evrak_ti,@cha_HalRusum,@cha_HalNavlunTut,@cha_HalRehinFuture,@cha_HalKomisyon,@cha_Vade_Farki_Yuz,@cha_karsisrmrkkodu,@cha_EXIMkodu,@cha_HalRehinSandikmiktari,@cha_HalSandikVrMiktar,@cha_HalSandikTutari,@cha_HalSandikKDVTutari,@cha_HalrehinSandikTutari,@cha_Tevkifat_turu,@cha_ticaret_turu,@cha_otvtutari,@cha_otvvergisiz_fl,@cha_projekodu,@cha_sozlesme_DBCno,@cha_sozlesme_RECno,@cha_yat_tes_kodu,@cha_ciro_cari_kodu,@cha_oivergisiz_fl,@cha_meblag_ana_doviz_icin_gecersiz_fl,@cha_meblag_alt_doviz_icin_gecersiz_fl,@cha_meblag_orj_doviz_icin_gecersiz_fl,@cha_ciroprim_DBCno,@cha_ciroprim_RECno,@cha_HalHamaliyeKdv,@cha_HalHamaliyeVergisiz_fl);UPDATE CARI_HESAP_HAREKETLERI SET cha_RECid_RECno=cha_RECno WHERE cha_RECid_RECno=-1";
            using (SqlConnection cn = new SqlConnection(Config.GetConfig.GetValue(CParams.ConStr)))
            {
                using (SqlCommand cmd = new SqlCommand(sql, cn))
                {
                    cmd.Parameters.Add("@cha_RECid_DBCno", SqlDbType.SmallInt).Value = 0;
                    cmd.Parameters.Add("@cha_RECid_RECno", SqlDbType.Int).Value = -1; //geri dönüp identity alanın değerini buraya set edicez
                    cmd.Parameters.Add("@cha_SpecRecNo", SqlDbType.Int).Value = 0;
                    cmd.Parameters.Add("@cha_iptal", SqlDbType.Bit).Value = false;
                    cmd.Parameters.Add("@cha_fileid", SqlDbType.SmallInt).Value = 51;
                    cmd.Parameters.Add("@cha_hidden", SqlDbType.Bit).Value = false;
                    cmd.Parameters.Add("@cha_kilitli", SqlDbType.Bit).Value = false;
                    cmd.Parameters.Add("@cha_degisti", SqlDbType.Bit).Value = false;
                    cmd.Parameters.Add("@cha_CheckSum", SqlDbType.Int).Value = 0;
                    cmd.Parameters.Add("@cha_create_user", SqlDbType.SmallInt).Value = 0;
                    cmd.Parameters.Add("@cha_create_date", SqlDbType.DateTime).Value = DateTime.Now;
                    cmd.Parameters.Add("@cha_lastup_user", SqlDbType.SmallInt).Value = 0;
                    cmd.Parameters.Add("@cha_lastup_date", SqlDbType.DateTime).Value = DateTime.Now;
                    cmd.Parameters.Add("@cha_special1", SqlDbType.VarChar).Value = "";
                    cmd.Parameters.Add("@cha_special2", SqlDbType.VarChar).Value = "";
                    cmd.Parameters.Add("@cha_special3", SqlDbType.VarChar).Value = "";
                    cmd.Parameters.Add("@cha_firmano", SqlDbType.Int).Value = 0;
                    cmd.Parameters.Add("@cha_subeno", SqlDbType.Int).Value = 0;
                    cmd.Parameters.Add("@cha_tarihi", SqlDbType.DateTime).Value = tarih;
                    cmd.Parameters.Add("@cha_tip", SqlDbType.TinyInt).Value = tip;
                    cmd.Parameters.Add("@cha_cinsi", SqlDbType.TinyInt).Value = cins;
                    cmd.Parameters.Add("@cha_normal_Iade", SqlDbType.TinyInt).Value = normIade;
                    cmd.Parameters.Add("@cha_evrak_tip", SqlDbType.TinyInt).Value = evrTip;
                    cmd.Parameters.Add("@cha_satir_no", SqlDbType.Int).Value = satir;
                    cmd.Parameters.Add("@cha_evrakno_seri", SqlDbType.VarChar).Value = seri;
                    cmd.Parameters.Add("@cha_evrakno_sira", SqlDbType.Int).Value = sira;
                    cmd.Parameters.Add("@cha_belge_no", SqlDbType.VarChar).Value = belgeNo;
                    cmd.Parameters.Add("@cha_belge_tarih", SqlDbType.DateTime).Value = new DateTime(tarih.Year, tarih.Month, tarih.Day);
                    cmd.Parameters.Add("@cha_cari_cins", SqlDbType.TinyInt).Value = 0;
                    cmd.Parameters.Add("@cha_kod", SqlDbType.VarChar).Value = cariKodu;
                    cmd.Parameters.Add("@cha_kasa_hizmet", SqlDbType.TinyInt).Value = hizTip;
                    cmd.Parameters.Add("@cha_kasa_hizkod", SqlDbType.VarChar).Value = kasaHizKod;
                    cmd.Parameters.Add("@cha_d_kurtar", SqlDbType.DateTime).Value = "1899-12-30 00:00:00";
                    cmd.Parameters.Add("@cha_d_cins", SqlDbType.TinyInt).Value = 0;
                    cmd.Parameters.Add("@cha_d_kur", SqlDbType.Float).Value = 1;
                    cmd.Parameters.Add("@cha_altd_kur", SqlDbType.Float).Value = "1,4907";
                    cmd.Parameters.Add("@cha_grupno", SqlDbType.TinyInt).Value = 0;
                    cmd.Parameters.Add("@cha_meblag", SqlDbType.Float).Value = meblag;
                    cmd.Parameters.Add("@cha_vade", SqlDbType.Int).Value = vadeGun;
                    cmd.Parameters.Add("@cha_fis_tarih", SqlDbType.DateTime).Value = "1899-12-30 00:00:00";
                    cmd.Parameters.Add("@cha_fis_sirano", SqlDbType.Int).Value = 0;
                    cmd.Parameters.Add("@cha_ft_iskonto1", SqlDbType.Float).Value = 0;
                    cmd.Parameters.Add("@cha_ft_iskonto2", SqlDbType.Float).Value = 0;
                    cmd.Parameters.Add("@cha_ft_iskonto3", SqlDbType.Float).Value = 0;
                    cmd.Parameters.Add("@cha_ft_iskonto4", SqlDbType.Float).Value = 0;
                    cmd.Parameters.Add("@cha_ft_iskonto5", SqlDbType.Float).Value = 0;
                    cmd.Parameters.Add("@cha_ft_iskonto6", SqlDbType.Float).Value = 0;
                    cmd.Parameters.Add("@cha_ft_masraf1", SqlDbType.Float).Value = 0;
                    cmd.Parameters.Add("@cha_ft_masraf2", SqlDbType.Float).Value = 0;
                    cmd.Parameters.Add("@cha_ft_masraf3", SqlDbType.Float).Value = 0;
                    cmd.Parameters.Add("@cha_ft_masraf4", SqlDbType.Float).Value = 0;
                    cmd.Parameters.Add("@cha_vergi1", SqlDbType.Float).Value = 0;
                    cmd.Parameters.Add("@cha_vergi2", SqlDbType.Float).Value = 0;
                    cmd.Parameters.Add("@cha_vergi3", SqlDbType.Float).Value = 0;
                    cmd.Parameters.Add("@cha_vergi4", SqlDbType.Float).Value = 0;
                    cmd.Parameters.Add("@cha_vergi5", SqlDbType.Float).Value = 0;
                    cmd.Parameters.Add("@cha_vergi6", SqlDbType.Float).Value = 0;
                    cmd.Parameters.Add("@cha_vergi7", SqlDbType.Float).Value = 0;
                    cmd.Parameters.Add("@cha_vergi8", SqlDbType.Float).Value = 0;
                    cmd.Parameters.Add("@cha_vergi9", SqlDbType.Float).Value = 0;
                    cmd.Parameters.Add("@cha_vergi10", SqlDbType.Float).Value = 0;
                    cmd.Parameters.Add("@cha_yuvarlama", SqlDbType.Float).Value = 0;
                    cmd.Parameters.Add("@cha_tpoz", SqlDbType.TinyInt).Value = 0;
                    cmd.Parameters.Add("@cha_aciklama", SqlDbType.VarChar).Value = "";
                    cmd.Parameters.Add("@cha_trefno", SqlDbType.VarChar).Value = refNo; //çek,kredi kartı,senet,havale referans numaraları
                    cmd.Parameters.Add("@cha_sntck_poz", SqlDbType.TinyInt).Value = senetcekPoz;
                    cmd.Parameters.Add("@cha_karsidcinsi", SqlDbType.TinyInt).Value = 0;
                    cmd.Parameters.Add("@cha_karsid_kur", SqlDbType.Float).Value = 1;
                    cmd.Parameters.Add("@cha_karsidgrupno", SqlDbType.TinyInt).Value = karsidgrupno;
                    cmd.Parameters.Add("@cha_srmrkkodu", SqlDbType.VarChar).Value = srmMerkez;
                    cmd.Parameters.Add("@cha_reftarihi", SqlDbType.DateTime).Value = "1899-12-30 00:00:00";
                    cmd.Parameters.Add("@cha_odeme_arr1", SqlDbType.Float).Value = 0;
                    cmd.Parameters.Add("@cha_odeme_arr2", SqlDbType.Float).Value = 0;
                    cmd.Parameters.Add("@cha_odeme_arr3", SqlDbType.Float).Value = 0;
                    cmd.Parameters.Add("@cha_odeme_arr4", SqlDbType.Float).Value = 0;
                    cmd.Parameters.Add("@cha_odeme_arr5", SqlDbType.Float).Value = 0;
                    cmd.Parameters.Add("@cha_odeme_arr6", SqlDbType.Float).Value = 0;
                    cmd.Parameters.Add("@cha_odeme_arr7", SqlDbType.Float).Value = 0;
                    cmd.Parameters.Add("@cha_odeme_arr8", SqlDbType.Float).Value = 0;
                    cmd.Parameters.Add("@cha_miktari", SqlDbType.Float).Value = 0;
                    cmd.Parameters.Add("@cha_aratoplam", SqlDbType.Float).Value = meblag;
                    cmd.Parameters.Add("@cha_vergipntr", SqlDbType.TinyInt).Value = 0;
                    cmd.Parameters.Add("@cha_istisnakodu", SqlDbType.TinyInt).Value = 0;
                    cmd.Parameters.Add("@cha_ver_tev_carpani", SqlDbType.Float).Value = 0;
                    cmd.Parameters.Add("@cha_stopaj", SqlDbType.Float).Value = 0;
                    cmd.Parameters.Add("@cha_savsandesfonu", SqlDbType.Float).Value = 0;
                    cmd.Parameters.Add("@cha_vergisiz_fl", SqlDbType.Bit).Value = false;
                    cmd.Parameters.Add("@cha_satici_kodu", SqlDbType.VarChar).Value = plasiyerKod;
                    cmd.Parameters.Add("@cha_mustahsil_borsa", SqlDbType.Float).Value = 0;
                    cmd.Parameters.Add("@cha_mustahsil_bagkur", SqlDbType.Float).Value = 0;
                    cmd.Parameters.Add("@cha_mustahsil_diger", SqlDbType.Float).Value = 0;
                    cmd.Parameters.Add("@cha_HalMSDF", SqlDbType.Float).Value = 0;
                    cmd.Parameters.Add("@cha_HalHamaliye", SqlDbType.Float).Value = 0;
                    cmd.Parameters.Add("@cha_HalStopaj", SqlDbType.Float).Value = 0;
                    cmd.Parameters.Add("@cha_HalKomisyonu", SqlDbType.Float).Value = 0;
                    cmd.Parameters.Add("@cha_StFonPntr", SqlDbType.TinyInt).Value = 0;
                    cmd.Parameters.Add("@cha_pos_hareketi", SqlDbType.Bit).Value = false;
                    cmd.Parameters.Add("@cha_vardiya_tarihi", SqlDbType.DateTime).Value = "1899-12-30 00:00:00";
                    cmd.Parameters.Add("@cha_vardiya_no", SqlDbType.TinyInt).Value = 0;
                    cmd.Parameters.Add("@cha_vardiya_evrak_ti", SqlDbType.TinyInt).Value = 0;
                    cmd.Parameters.Add("@cha_HalRusum", SqlDbType.Float).Value = 0;
                    cmd.Parameters.Add("@cha_HalNavlunTut", SqlDbType.Float).Value = 0;
                    cmd.Parameters.Add("@cha_HalRehinFuture", SqlDbType.Float).Value = 0;
                    cmd.Parameters.Add("@cha_HalKomisyon", SqlDbType.Float).Value = 0;
                    cmd.Parameters.Add("@cha_Vade_Farki_Yuz", SqlDbType.Float).Value = 0;
                    cmd.Parameters.Add("@cha_karsisrmrkkodu", SqlDbType.VarChar).Value = srmMerkez;
                    cmd.Parameters.Add("@cha_EXIMkodu", SqlDbType.VarChar).Value = "";
                    cmd.Parameters.Add("@cha_HalRehinSandikmiktari", SqlDbType.Float).Value = 0;
                    cmd.Parameters.Add("@cha_HalSandikVrMiktar", SqlDbType.Float).Value = 0;
                    cmd.Parameters.Add("@cha_HalSandikTutari", SqlDbType.Float).Value = 0;
                    cmd.Parameters.Add("@cha_HalSandikKDVTutari", SqlDbType.Float).Value = 0;
                    cmd.Parameters.Add("@cha_HalrehinSandikTutari", SqlDbType.Float).Value = 0;
                    cmd.Parameters.Add("@cha_Tevkifat_turu", SqlDbType.TinyInt).Value = 0;
                    cmd.Parameters.Add("@cha_ticaret_turu", SqlDbType.TinyInt).Value = 0;
                    cmd.Parameters.Add("@cha_otvtutari", SqlDbType.Float).Value = 0;
                    cmd.Parameters.Add("@cha_otvvergisiz_fl", SqlDbType.Bit).Value = false;
                    cmd.Parameters.Add("@cha_projekodu", SqlDbType.VarChar).Value = "";
                    cmd.Parameters.Add("@cha_sozlesme_DBCno", SqlDbType.SmallInt).Value = 0;
                    cmd.Parameters.Add("@cha_sozlesme_RECno", SqlDbType.Int).Value = 0;
                    cmd.Parameters.Add("@cha_yat_tes_kodu", SqlDbType.VarChar).Value = "";
                    cmd.Parameters.Add("@cha_ciro_cari_kodu", SqlDbType.VarChar).Value = "";
                    cmd.Parameters.Add("@cha_oivergisiz_fl", SqlDbType.Bit).Value = false;
                    cmd.Parameters.Add("@cha_meblag_ana_doviz_icin_gecersiz_fl", SqlDbType.TinyInt).Value = 0;
                    cmd.Parameters.Add("@cha_meblag_alt_doviz_icin_gecersiz_fl", SqlDbType.TinyInt).Value = 0;
                    cmd.Parameters.Add("@cha_meblag_orj_doviz_icin_gecersiz_fl", SqlDbType.TinyInt).Value = 0;
                    cmd.Parameters.Add("@cha_ciroprim_DBCno", SqlDbType.SmallInt).Value = 0;
                    cmd.Parameters.Add("@cha_ciroprim_RECno", SqlDbType.Int).Value = 0;
                    cmd.Parameters.Add("@cha_HalHamaliyeKdv", SqlDbType.Float).Value = 0;
                    cmd.Parameters.Add("@cha_HalHamaliyeVergisiz_fl", SqlDbType.Bit).Value = false;

                    cn.Open();
                    cmd.ExecuteNonQuery();

                    switch (tahsilatTipi)
                    {
                        case TahsilatTipi.Cek:
                            OdemeEmriEkle(refNo, vade, meblag, cariKodu, subeAdi, hesapNo, cekNo, cariKodu, seri, sira, kesideYeri, "", 1, tarih);
                            break;
                        case TahsilatTipi.KrediKarti:
                            OdemeEmriEkle(refNo, vade, meblag, bankaAdi, subeAdi, hesapNo, refNo, cariKodu, seri, sira, "", kartNo, 0, tarih);
                            break;
                        case TahsilatTipi.Havale:
                            OdemeEmriEkle(refNo, vade, meblag, kasaHizKod, subeAdi, hesapNo, "", cariKodu, seri, sira, "", "", 2, tarih);
                            break;
                        case TahsilatTipi.Senet:
                            OdemeEmriEkle(refNo, vade, meblag, kasaHizKod, subeAdi, hesapNo, refNo, cariKodu, seri, sira, "", "", 3, tarih);
                            break;
                    }
                }
                cn.Close();
            }
            return "";
        }
        public void OdemeEmriEkle(string refNo, DateTime vade, decimal tutar, string neredeHesapKodu, string sube, string hesapno, string cekno, string cari, string evrakSeri, int evrakSira, string kesideYeri, string kredikartNo, int islemTipi, DateTime tarih)
        {
            int cariCins = 0;
            int cariGrup = 0;
            int karsiCariCins = 4;
            int karsiCariGrupKodu = 0;
            int sonPoz = 0;
            int sckTip = 0;

            switch (islemTipi)
            {
                case 0://kredi kartı
                    cariCins = 0;
                    cariGrup = 0;
                    karsiCariCins = 2;
                    karsiCariGrupKodu = 7;
                    sonPoz = 2;
                    sckTip = 6;
                    break;
                case 1: //çek
                    cariCins = 0;
                    cariGrup = 0;
                    karsiCariCins = 4;
                    karsiCariGrupKodu = 0;
                    sonPoz = 0;
                    sckTip = 0;
                    break;
                case 2: //havale
                    cariCins = 0;
                    cariGrup = 0;
                    karsiCariCins = 2;
                    karsiCariGrupKodu = 9;
                    sonPoz = 2;
                    sckTip = 4;
                    break;
                case 3: //senet
                    cariCins = 0;
                    cariGrup = 0;
                    karsiCariCins = 4;
                    karsiCariGrupKodu = 0;
                    sonPoz = 0;
                    sckTip = 1;
                    break;
                default:
                    break;
            }

            string sql = "if not exists(select sck_refno from ODEME_EMIRLERI where sck_refno=@sck_refno) insert into ODEME_EMIRLERI (sck_RECid_DBCno,sck_RECid_RECno,sck_SpecRECno,sck_iptal,sck_fileid,sck_hidden,sck_kilitli,sck_degisti,sck_checksum,sck_create_user,sck_create_date,sck_lastup_user,sck_lastup_date,sck_special1,sck_special2,sck_special3,sck_firmano,sck_subeno,sck_tip,sck_refno,sck_bankano,sck_borclu,sck_vdaire_no,sck_vade,sck_tutar,sck_doviz,sck_odenen,sck_degerleme_islendi,sck_banka_adres1,sck_sube_adres2,sck_borclu_tel,sck_hesapno_sehir,sck_no,sck_duzen_tarih,sck_sahip_cari_cins,sck_sahip_cari_kodu,sck_sahip_cari_grupno,sck_nerede_cari_cins,sck_nerede_cari_kodu,sck_nerede_cari_grupno,sck_ilk_hareket_tarihi,sck_ilk_evrak_seri,sck_ilk_evrak_sira_no,sck_ilk_evrak_satir_no,sck_son_hareket_tarihi,sck_doviz_kur,sck_sonpoz,sck_imza,sck_srmmrk,sck_kesideyeri,Sck_TCMB_Banka_kodu,Sck_TCMB_Sube_kodu,Sck_TCMB_il_kodu,SckTasra_fl,sck_projekodu,sck_masraf1,sck_masraf1_isleme,sck_masraf2,sck_masraf2_isleme,sck_odul_katkisi_tutari,sck_servis_komisyon_tutari,sck_erken_odeme_faiz_tutari,sck_odul_katkisi_tutari_islendi_fl,sck_servis_komisyon_tutari_islendi_fl,sck_erken_odeme_faiz_tutari_islendi_fl,sck_kredi_karti_tipi,sck_taksit_sayisi,sck_kacinci_taksit,sck_uye_isyeri_no,sck_kredi_karti_no,sck_provizyon_kodu) values (@sck_RECid_DBCno,@sck_RECid_RECno,@sck_SpecRECno,@sck_iptal,@sck_fileid,@sck_hidden,@sck_kilitli,@sck_degisti,@sck_checksum,@sck_create_user,@sck_create_date,@sck_lastup_user,@sck_lastup_date,@sck_special1,@sck_special2,@sck_special3,@sck_firmano,@sck_subeno,@sck_tip,@sck_refno,@sck_bankano,@sck_borclu,@sck_vdaire_no,@sck_vade,@sck_tutar,@sck_doviz,@sck_odenen,@sck_degerleme_islendi,@sck_banka_adres1,@sck_sube_adres2,@sck_borclu_tel,@sck_hesapno_sehir,@sck_no,@sck_duzen_tarih,@sck_sahip_cari_cins,@sck_sahip_cari_kodu,@sck_sahip_cari_grupno,@sck_nerede_cari_cins,@sck_nerede_cari_kodu,@sck_nerede_cari_grupno,@sck_ilk_hareket_tarihi,@sck_ilk_evrak_seri,@sck_ilk_evrak_sira_no,@sck_ilk_evrak_satir_no,@sck_son_hareket_tarihi,@sck_doviz_kur,@sck_sonpoz,@sck_imza,@sck_srmmrk,@sck_kesideyeri,@Sck_TCMB_Banka_kodu,@Sck_TCMB_Sube_kodu,@Sck_TCMB_il_kodu,@SckTasra_fl,@sck_projekodu,@sck_masraf1,@sck_masraf1_isleme,@sck_masraf2,@sck_masraf2_isleme,@sck_odul_katkisi_tutari,@sck_servis_komisyon_tutari,@sck_erken_odeme_faiz_tutari,@sck_odul_katkisi_tutari_islendi_fl,@sck_servis_komisyon_tutari_islendi_fl,@sck_erken_odeme_faiz_tutari_islendi_fl,@sck_kredi_karti_tipi,@sck_taksit_sayisi,@sck_kacinci_taksit,@sck_uye_isyeri_no,@sck_kredi_karti_no,@sck_provizyon_kodu);UPDATE ODEME_EMIRLERI SET sck_RECid_RECno=sck_RECno WHERE sck_RECid_RECno=-99";
            using (SqlConnection cn = new SqlConnection(Config.GetConfig.GetValue(CParams.ConStr)))
            {
                using (SqlCommand cmd = new SqlCommand(sql, cn))
                {
                    cmd.Parameters.Add("@sck_RECid_DBCno", SqlDbType.SmallInt).Value = 0;
                    cmd.Parameters.Add("@sck_RECid_RECno", SqlDbType.Int).Value = -99;
                    cmd.Parameters.Add("@sck_SpecRECno", SqlDbType.Int).Value = 0;
                    cmd.Parameters.Add("@sck_iptal", SqlDbType.Bit).Value = false;
                    cmd.Parameters.Add("@sck_fileid", SqlDbType.SmallInt).Value = 54;
                    cmd.Parameters.Add("@sck_hidden", SqlDbType.Bit).Value = false;
                    cmd.Parameters.Add("@sck_kilitli", SqlDbType.Bit).Value = false;
                    cmd.Parameters.Add("@sck_degisti", SqlDbType.Bit).Value = false;
                    cmd.Parameters.Add("@sck_checksum", SqlDbType.Int).Value = 0;
                    cmd.Parameters.Add("@sck_create_user", SqlDbType.SmallInt).Value = 0;
                    cmd.Parameters.Add("@sck_create_date", SqlDbType.DateTime).Value = DateTime.Now;
                    cmd.Parameters.Add("@sck_lastup_user", SqlDbType.SmallInt).Value = 0;
                    cmd.Parameters.Add("@sck_lastup_date", SqlDbType.DateTime).Value = DateTime.Now;
                    cmd.Parameters.Add("@sck_special1", SqlDbType.VarChar).Value = "";
                    cmd.Parameters.Add("@sck_special2", SqlDbType.VarChar).Value = "";
                    cmd.Parameters.Add("@sck_special3", SqlDbType.VarChar).Value = "";
                    cmd.Parameters.Add("@sck_firmano", SqlDbType.Int).Value = 0;
                    cmd.Parameters.Add("@sck_subeno", SqlDbType.Int).Value = 0;
                    cmd.Parameters.Add("@sck_tip", SqlDbType.TinyInt).Value = sckTip;
                    cmd.Parameters.Add("@sck_refno", SqlDbType.VarChar, 25).Value = refNo; //çek kredi kart vs no
                    cmd.Parameters.Add("@sck_bankano", SqlDbType.VarChar).Value = "";
                    cmd.Parameters.Add("@sck_borclu", SqlDbType.VarChar).Value = "";
                    cmd.Parameters.Add("@sck_vdaire_no", SqlDbType.VarChar).Value = "";
                    cmd.Parameters.Add("@sck_vade", SqlDbType.DateTime).Value = vade;
                    cmd.Parameters.Add("@sck_tutar", SqlDbType.Float).Value = tutar;
                    cmd.Parameters.Add("@sck_doviz", SqlDbType.TinyInt).Value = 0;
                    cmd.Parameters.Add("@sck_odenen", SqlDbType.Float).Value = 0;
                    cmd.Parameters.Add("@sck_degerleme_islendi", SqlDbType.TinyInt).Value = 0;
                    cmd.Parameters.Add("@sck_banka_adres1", SqlDbType.VarChar).Value = "";
                    cmd.Parameters.Add("@sck_sube_adres2", SqlDbType.VarChar).Value = sube;
                    cmd.Parameters.Add("@sck_borclu_tel", SqlDbType.VarChar).Value = "";
                    cmd.Parameters.Add("@sck_hesapno_sehir", SqlDbType.VarChar, 20).Value = hesapno;
                    cmd.Parameters.Add("@sck_no", SqlDbType.VarChar).Value = cekno;
                    cmd.Parameters.Add("@sck_duzen_tarih", SqlDbType.DateTime).Value = "1899-12-30 00:00:00";
                    cmd.Parameters.Add("@sck_sahip_cari_cins", SqlDbType.TinyInt).Value = cariCins;
                    cmd.Parameters.Add("@sck_sahip_cari_kodu", SqlDbType.VarChar).Value = cari;
                    cmd.Parameters.Add("@sck_sahip_cari_grupno", SqlDbType.TinyInt).Value = cariGrup;
                    cmd.Parameters.Add("@sck_nerede_cari_cins", SqlDbType.TinyInt).Value = karsiCariCins;
                    cmd.Parameters.Add("@sck_nerede_cari_kodu", SqlDbType.VarChar).Value = neredeHesapKodu;
                    cmd.Parameters.Add("@sck_nerede_cari_grupno", SqlDbType.TinyInt).Value = karsiCariGrupKodu;
                    cmd.Parameters.Add("@sck_ilk_hareket_tarihi", SqlDbType.DateTime).Value = new DateTime(tarih.Year, tarih.Month, tarih.Day); ;
                    cmd.Parameters.Add("@sck_ilk_evrak_seri", SqlDbType.VarChar).Value = evrakSeri;
                    cmd.Parameters.Add("@sck_ilk_evrak_sira_no", SqlDbType.Int).Value = evrakSira;
                    cmd.Parameters.Add("@sck_ilk_evrak_satir_no", SqlDbType.Int).Value = 0;
                    cmd.Parameters.Add("@sck_son_hareket_tarihi", SqlDbType.DateTime).Value = new DateTime(tarih.Year, tarih.Month, tarih.Day); ;
                    cmd.Parameters.Add("@sck_doviz_kur", SqlDbType.Float).Value = 1;
                    cmd.Parameters.Add("@sck_sonpoz", SqlDbType.TinyInt).Value = sonPoz;
                    cmd.Parameters.Add("@sck_imza", SqlDbType.TinyInt).Value = 0;
                    cmd.Parameters.Add("@sck_srmmrk", SqlDbType.VarChar).Value = 1;
                    cmd.Parameters.Add("@sck_kesideyeri", SqlDbType.VarChar).Value = kesideYeri;
                    cmd.Parameters.Add("@Sck_TCMB_Banka_kodu", SqlDbType.VarChar).Value = "";
                    cmd.Parameters.Add("@Sck_TCMB_Sube_kodu", SqlDbType.VarChar).Value = "";
                    cmd.Parameters.Add("@Sck_TCMB_il_kodu", SqlDbType.VarChar).Value = "";
                    cmd.Parameters.Add("@SckTasra_fl", SqlDbType.Bit).Value = false;
                    cmd.Parameters.Add("@sck_projekodu", SqlDbType.VarChar).Value = "";
                    cmd.Parameters.Add("@sck_masraf1", SqlDbType.Float).Value = 0;
                    cmd.Parameters.Add("@sck_masraf1_isleme", SqlDbType.TinyInt).Value = 0;
                    cmd.Parameters.Add("@sck_masraf2", SqlDbType.Float).Value = 0;
                    cmd.Parameters.Add("@sck_masraf2_isleme", SqlDbType.TinyInt).Value = 0;
                    cmd.Parameters.Add("@sck_odul_katkisi_tutari", SqlDbType.Float).Value = 0;
                    cmd.Parameters.Add("@sck_servis_komisyon_tutari", SqlDbType.Float).Value = 0;
                    cmd.Parameters.Add("@sck_erken_odeme_faiz_tutari", SqlDbType.Float).Value = 0;
                    cmd.Parameters.Add("@sck_odul_katkisi_tutari_islendi_fl", SqlDbType.Bit).Value = false;
                    cmd.Parameters.Add("@sck_servis_komisyon_tutari_islendi_fl", SqlDbType.Bit).Value = false;
                    cmd.Parameters.Add("@sck_erken_odeme_faiz_tutari_islendi_fl", SqlDbType.Bit).Value = false;
                    cmd.Parameters.Add("@sck_kredi_karti_tipi", SqlDbType.TinyInt).Value = 0;
                    cmd.Parameters.Add("@sck_taksit_sayisi", SqlDbType.SmallInt).Value = 0;
                    cmd.Parameters.Add("@sck_kacinci_taksit", SqlDbType.SmallInt).Value = 0;
                    cmd.Parameters.Add("@sck_uye_isyeri_no", SqlDbType.VarChar).Value = "";
                    cmd.Parameters.Add("@sck_kredi_karti_no", SqlDbType.VarChar, 16).Value = kredikartNo;
                    cmd.Parameters.Add("@sck_provizyon_kodu", SqlDbType.VarChar).Value = "";

                    cn.Open();
                    cmd.ExecuteNonQuery();
                }
                cn.Close();
            }
        }
        public string TahsilatReferansNo(TahsilatTipi tip)
        {
            int sck_tip = -1;
            string refno = "";
            switch (tip)
            {
                case TahsilatTipi.Cek:
                    refno = "MC";
                    sck_tip = 0;
                    break;
                case TahsilatTipi.Senet:
                    refno = "MS";
                    sck_tip = 1;
                    break;
                case TahsilatTipi.KrediKarti:
                    refno = "MK";
                    sck_tip = 6;
                    break;
                case TahsilatTipi.Havale:
                    refno = "MH";
                    sck_tip = 4;
                    break;
            }
            string sql = string.Format("exec sp_executesql N'SELECT TOP 1 sck_refno FROM ODEME_EMIRLERI WITH ( NOLOCK , INDEX = NDX_ODEME_EMIRLERI_02 )  WHERE ((sck_tip={0} AND sck_refno<''{1}-000-000-{2}-ÿÿÿÿÿÿÿÿ'')) AND ((sck_refno like ''{1}-000-000-{2}-________'')) ORDER BY sck_tip DESC,sck_refno DESC'", sck_tip, refno, DateTime.Now.Year.ToString("0000"));
            object sonuc = DataLayer.GetLayer.ExecScalar(sql);
            string referans_no = "";
            if (sonuc != null)
            {
                if (sonuc != DBNull.Value)
                {
                    string[] refval = sonuc.ToString().Split('-');
                    int lastno = Convert.ToInt32(refval[refval.Length - 1]);
                    referans_no = string.Format("{0}-000-000-{1}-{2}", refno, DateTime.Now.Year.ToString("0000"), (lastno + 1).ToString("00000000"));
                }
            }
            if (referans_no == "")
                referans_no = string.Format("{0}-000-000-{1}-{2}", refno, DateTime.Now.Year.ToString("0000"), "00000001");

            return referans_no;
        }
        public int[] SatisFaturasi_CariHar_EvrakTipi
        {
            get
            {
                return new int[] { 0, 6, 0, 63 };
            }
        }
        public int[] SatisFaturasi_StokHar_EvrakTipi
        {
            get
            {
                return new int[] { 1, 0, 0, 4 };
            }
        }
        public int[] SatisIrsaliyesi_StokHar_EvrakTipi
        {
            get
            {
                return new int[] { 1, 0, 0, 1 };
            }
        }
        public int[] SatisIadeFaturasi_CariHar_EvrakTipi
        {
            get
            {
                return new int[] { 0, 6, 1, 63 };
            }
        }
        public int[] SatisIadeFaturasi_StokHar_EvrakTipi
        {
            get
            {
                return new int[] { 1, 0, 1, 4 };
            }
        }
        public int[] AlinanSiparisEvrakTipi
        {
            get
            {
                return new int[] { 0, 0 };
            }
        }
        public int[] DepoSevkEvrakTipi
        {
            get
            {
                return new int[] { 2, 6, 0, 2 };
            }
        }
        public int[] TahsilatEvrakTipi
        {
            get { throw new NotImplementedException(); }
        }
        public int[] IadeFaturasi_CariHar_EvrakTipi
        {
            get
            {
                return new int[] { 1, 6, 1, 0 };
            }
        }
        public int[] IadeFaturasi_StokHar_EvrakTipi
        {
            get
            {
                return new int[] { 0, 0, 1, 3 };
            }
        }
        public Dictionary<int, int> KdvSira
        {
            get
            {
                Dictionary<int, int> kdvler = new Dictionary<int, int>();
                using (SqlConnection cn = new SqlConnection(Config.GetConfig.GetValue(CParams.ConStr)))
                {
                    cn.Open();
                    using (SqlCommand cmd = new SqlCommand("", cn))
                    {
                        cmd.CommandText = "exec sp_executesql N'select cast(0 as varchar) + '';'' + cast(dbo.fn_VergiYuzde(1) as varchar) + '';'' + cast(dbo.fn_VergiYuzde(2) as varchar) + '';'' + cast(dbo.fn_VergiYuzde(3) as varchar) + '';'' + cast(dbo.fn_VergiYuzde(4) as varchar) + '';'' + cast(dbo.fn_VergiYuzde(5) as varchar) + '';'' + cast(dbo.fn_VergiYuzde(6) as varchar) + '';'' + cast(dbo.fn_VergiYuzde(7) as varchar) + '';'' + cast(dbo.fn_VergiYuzde(8) as varchar) + '';'' + cast(dbo.fn_VergiYuzde(9) as varchar)'";
                        object sonuc = cmd.ExecuteScalar();
                        if (sonuc != null)
                        {
                            string[] kdv = sonuc.ToString().Split(';');
                            for (int i = 0; i < kdv.Length; i++)
                                kdvler.Add(i, int.Parse(kdv[i]));
                        }
                    }
                    cn.Close();
                }
                return kdvler;
            }
        }
        public int MaxEvrakNo(SyncEvrakTipi tip, string seri)
        {
            int sira = 1;
            string txtsql = string.Empty;
            switch (tip)
            {
                case SyncEvrakTipi.SatisFaturasi:
                    txtsql = string.Format("SELECT     MAX(cha_evrakno_sira) + 1 FROM         CARI_HESAP_HAREKETLERI WHERE     (cha_tip = 0) AND (cha_cinsi = 6) AND (cha_normal_Iade = 0) AND (cha_evrak_tip = 63) AND (cha_evrakno_seri = '{0}')", seri);
                    break;
                case SyncEvrakTipi.AlinanSiparis:
                    txtsql = string.Format("SELECT     MAX(sip_evrakno_sira) + 1 FROM         SIPARISLER  WHERE     (sip_tip = 0) AND (sip_cins = 0) AND (sip_evrakno_seri = '{0}')", seri);
                    break;
            }
            DataTable dt = DataLayer.GetLayer.FillData(txtsql);
            if (dt.Rows.Count > 0)
                sira = Convert.ToInt32(dt.Rows[0][0]);
            return sira;
        }
        public bool EvrakVarmi(string seri, int sira, SyncEvrakTipi tip)
        {
            bool durum = false;
            string txtsql = string.Empty;
            switch (tip)
            {
                case SyncEvrakTipi.SatisFaturasi:
                    txtsql = string.Format("exec sp_executesql N'SELECT     cha_evrakno_sira FROM         CARI_HESAP_HAREKETLERI WHERE     (cha_tip = 0) AND (cha_cinsi = 6) AND (cha_normal_Iade = 0) AND (cha_evrak_tip = 63) AND (cha_evrakno_seri = ''{0}'') AND (cha_evrakno_sira={1})'", seri, sira);
                    break;
                case SyncEvrakTipi.AlinanSiparis:
                    txtsql = string.Format("exec sp_executesql N'SELECT     sip_evrakno_sira FROM         SIPARISLER  WHERE     (sip_tip = 0) AND (sip_cins = 0) AND (sip_evrakno_seri = ''{0}'') AND (sip_evrakno_sira={1})'", seri, sira);
                    break;
                case SyncEvrakTipi.Tahsilat:
                    txtsql = string.Format("exec sp_executesql N'SELECT     cha_evrakno_sira FROM         CARI_HESAP_HAREKETLERI WHERE     (cha_tip = 1) AND (cha_normal_Iade = 0) AND (cha_evrak_tip = 1) AND (cha_evrakno_seri = ''{0}'') AND (cha_evrakno_sira={1})'", seri, sira);
                    break;
                case SyncEvrakTipi.IadeFaturasi:
                    txtsql = string.Format("exec sp_executesql N'SELECT     cha_evrakno_sira FROM         CARI_HESAP_HAREKETLERI WHERE     (cha_tip = 1) AND (cha_cinsi = 6) AND (cha_normal_Iade = 1) AND (cha_evrak_tip = 0) AND (cha_evrakno_seri = ''{0}'') AND (cha_evrakno_sira={1})'", seri, sira);
                    break;
                case SyncEvrakTipi.Transfer:
                    txtsql = string.Format("exec sp_executesql N'SELECT     sth_evrakno_sira FROM         STOK_HAREKETLERI WHERE     (sth_tip = 2) AND (sth_cins = 6) AND (sth_normal_iade = 0) AND (sth_evraktip = 2) AND (sth_evrakno_seri = ''{0}'') AND (sth_evrakno_sira = {1})'", seri, sira);
                    break;
            }
            DataTable dt = DataLayer.GetLayer.FillData(txtsql);
            if (dt.Rows.Count > 0)
                durum = true;
            return durum;
        }
        public string CariListeSql()
        {
            StringBuilder sb = new StringBuilder();
            sb.Append(" SELECT     CARI_HESAPLAR.cari_kod AS [Müşteri Kodu], CARI_HESAPLAR.cari_unvan1 AS [1.Ünvanı], CARI_HESAPLAR.cari_unvan2 AS [2.Ünvanı],  ");
            sb.Append(" ISNULL(CARI_HESAP_ADRESLERI.adr_adres_no, 1) AS [Adres No], CARI_HESAP_ADRESLERI.adr_cadde AS Cadde, CARI_HESAP_ADRESLERI.adr_sokak AS Sokak,  ");
            sb.Append(" CARI_HESAP_ADRESLERI.adr_il AS İl, CARI_HESAP_ADRESLERI.adr_ilce AS İlçe, CARI_HESAPLAR.cari_RECno,isnull(CARI_HESAP_ADRESLERI.adr_adres_no,0) as adres ");
            sb.Append(" FROM         CARI_HESAPLAR LEFT OUTER JOIN CARI_HESAP_ADRESLERI ON CARI_HESAPLAR.cari_kod = CARI_HESAP_ADRESLERI.adr_cari_kod ");
            return sb.ToString();
        }
        public string RouteListeSql()
        {
            StringBuilder sb = new StringBuilder();
            sb.Append(" SELECT     MERCHANT_ROUTE.VISIT_NO, CARI_HESAPLAR.cari_kod, CARI_HESAPLAR.cari_unvan1,MERCHANT_ROUTE.CUSTOMER_ID, MERCHANT_ROUTE.ADDRESS_ID");
            sb.Append(" FROM         MERCHANT_ROUTE INNER JOIN CARI_HESAPLAR ON MERCHANT_ROUTE.CUSTOMER_ID = CARI_HESAPLAR.cari_RECno ");
            sb.Append(" WHERE     (MERCHANT_ROUTE.WEEK_NO = @week) AND (MERCHANT_ROUTE.DAY_NO = @day) AND (MERCHANT_ROUTE.MERCHANT_ID = @pls) ORDER BY MERCHANT_ROUTE.VISIT_NO ");
            return sb.ToString();
        }
        public string RouteOlmayanCariler(int hafta)
        {
            StringBuilder sb = new StringBuilder();
            sb.Append("exec sp_executesql N'SELECT     CARI_HESAPLAR.cari_RECno, mer.ID, CARI_HESAP_ADRESLERI.adr_adres_no,(SELECT ISNULL(MAX(VISIT_NO), 0) + 1 FROM MERCHANT_ROUTE WHERE (MERCHANT_ID = mer.ID) AND (WEEK_NO = {0})) AS sira ");
            sb.Append(" FROM       CARI_HESAPLAR INNER JOIN CARI_HESAP_ADRESLERI ON CARI_HESAPLAR.cari_kod = CARI_HESAP_ADRESLERI.adr_cari_kod CROSS JOIN MERCHANT AS mer ");
            sb.Append(" WHERE     (CARI_HESAPLAR.cari_RECno NOT IN (SELECT CUSTOMER_ID FROM MERCHANT_ROUTE AS m1 WHERE (WEEK_NO = {0}) AND (MERCHANT_ID = mer.ID) GROUP BY CUSTOMER_ID))' ");
            return string.Format(sb.ToString(), hafta);
        }

        public int CariVade(string carikod)
        {
            int vade = 0;
            using (SqlConnection cn = new SqlConnection(Config.GetConfig.GetValue(CParams.ConStr)))
            {
                cn.Open();
                using (SqlCommand cmd = new SqlCommand(string.Format("SELECT     cari_odemeplan_no FROM         CARI_HESAPLAR WITH (NOLOCK) WHERE     (cari_kod = '{0}')", carikod), cn))
                {
                    object sonuc = cmd.ExecuteScalar();
                    if (sonuc != DBNull.Value)
                    {
                        vade = Convert.ToInt32(sonuc);
                    }
                }
                cn.Close();
            }
            return vade;
        }

        public int BankaTahsilSuresi(string bankaKod)
        {
            int vade = 0;
            using (SqlConnection cn = new SqlConnection(Config.GetConfig.GetValue(CParams.ConStr)))
            {
                cn.Open();
                using (SqlCommand cmd = new SqlCommand(string.Format("SELECT     ban_Ayni_banka_tahsil_suresi  FROM         BANKALAR  WHERE     (ban_kod = N'{0}')", bankaKod), cn))
                {
                    object sonuc = cmd.ExecuteScalar();
                    if (sonuc != DBNull.Value)
                    {
                        vade = Convert.ToInt32(sonuc);
                    }
                }
                cn.Close();
            }
            return vade;
        }
        private void TevkifatGuncelle(int evrakcins, string seri, int sira, Dictionary<string, decimal> tevkifatlar)
        {
            if (tevkifatlar.Count == 0)
            {
                return;
            }
            string sql = "";
            foreach (KeyValuePair<string, decimal> k in tevkifatlar)
            {
                sql += k.Key + "=@" + k.Key + ",";
            }
            sql = sql.Remove(sql.Length - 1);
            using (SqlConnection cn = new SqlConnection(Config.GetConfig.GetValue(CParams.ConStr)))
            {
                using (SqlCommand cmd = new SqlCommand(string.Format("UPDATE CARI_HESAP_HAREKETLERI SET {0} WHERE     (cha_evrak_tip = @cha_evrak_tip) AND (cha_evrakno_seri = @cha_evrakno_seri) AND (cha_evrakno_sira = @cha_evrakno_sira)", sql), cn) { CommandType = CommandType.Text })
                {
                    cmd.Parameters.Add("@cha_evrak_tip", SqlDbType.TinyInt).Value = evrakcins;
                    cmd.Parameters.Add("@cha_satir_no", SqlDbType.Int).Value = 0;
                    cmd.Parameters.Add("@cha_evrakno_seri", SqlDbType.VarChar).Value = seri;
                    cmd.Parameters.Add("@cha_evrakno_sira", SqlDbType.Int).Value = sira;

                    foreach (KeyValuePair<string, decimal> k in tevkifatlar)
                    {
                        cmd.Parameters.Add("@" + k.Key, SqlDbType.Float).Value = k.Value;
                    }
                    cn.Open();
                    cmd.ExecuteNonQuery();
                }
                cn.Close();
            }
        }

        public string TemsilciBazindaRoute()
        {
            StringBuilder sb = new StringBuilder();
            sb.Append("SELECT     CARI_HESAPLAR.cari_RECno, MERCHANT.ID, CARI_HESAP_ADRESLERI.adr_adres_no,");
            sb.Append("                          (SELECT     ISNULL(MAX(VISIT_NO), 0) + 1 AS Expr1");
            sb.Append("                            FROM          MERCHANT_ROUTE");
            sb.Append("                            WHERE      (MERCHANT_ID = MERCHANT.ID) AND (WEEK_NO = 1)) AS sira");
            sb.Append(" FROM         CARI_HESAPLAR INNER JOIN");
            sb.Append("                      CARI_HESAP_ADRESLERI ON CARI_HESAPLAR.cari_kod = CARI_HESAP_ADRESLERI.adr_cari_kod INNER JOIN");
            sb.Append("                      MERCHANT ON CARI_HESAPLAR.cari_temsilci_kodu = MERCHANT.CODE");
            sb.Append(" WHERE     (CARI_HESAPLAR.cari_temsilci_kodu <> '') AND (CARI_HESAPLAR.cari_RECno NOT IN");
            sb.Append("                          (SELECT     CUSTOMER_ID");
            sb.Append("                            FROM          MERCHANT_ROUTE");
            sb.Append("                            WHERE      (WEEK_NO = 1) AND (MERCHANT_ID = MERCHANT.ID)");
            sb.Append("                            GROUP BY CUSTOMER_ID))");
            sb.Append(" union all");
            sb.Append(" SELECT     CARI_HESAPLAR.cari_RECno, MERCHANT.ID, CARI_HESAP_ADRESLERI.adr_adres_no,");
            sb.Append("                          (SELECT     ISNULL(MAX(VISIT_NO), 0) + 1 AS Expr1");
            sb.Append("                            FROM          MERCHANT_ROUTE");
            sb.Append("                            WHERE      (MERCHANT_ID = MERCHANT.ID) AND (WEEK_NO = 1)) AS sira");
            sb.Append(" FROM         CARI_HESAPLAR INNER JOIN");
            sb.Append("                      CARI_HESAP_ADRESLERI ON CARI_HESAPLAR.cari_kod = CARI_HESAP_ADRESLERI.adr_cari_kod INNER JOIN");
            sb.Append("                      MERCHANT ON CARI_HESAP_ADRESLERI.adr_temsilci_kodu = MERCHANT.CODE");
            sb.Append(" WHERE     (CARI_HESAP_ADRESLERI.adr_temsilci_kodu <> '') AND (CARI_HESAPLAR.cari_RECno NOT IN");
            sb.Append("                          (SELECT     CUSTOMER_ID");
            sb.Append("                            FROM          MERCHANT_ROUTE AS MERCHANT_ROUTE_1");
            sb.Append("                            WHERE      (WEEK_NO = 1) AND (MERCHANT_ID = MERCHANT.ID) AND (ADDRESS_ID=CARI_HESAP_ADRESLERI.adr_adres_no)");
            sb.Append("                            GROUP BY CUSTOMER_ID))");

            //StringBuilder sb = new StringBuilder();
            //sb.Append(" SELECT     CARI_HESAPLAR.cari_RECno, MERCHANT.ID, CARI_HESAP_ADRESLERI.adr_RECno,(SELECT     ISNULL(MAX(VISIT_NO), 0) + 1 FROM MERCHANT_ROUTE WHERE (MERCHANT_ID = MERCHANT.ID) AND (WEEK_NO = 1)) AS sira FROM CARI_HESAPLAR INNER JOIN CARI_HESAP_ADRESLERI ON CARI_HESAPLAR.cari_kod = CARI_HESAP_ADRESLERI.adr_cari_kod INNER JOIN MERCHANT ON CARI_HESAPLAR.cari_temsilci_kodu = MERCHANT.CODE ");
            //sb.Append(" WHERE     (CARI_HESAPLAR.cari_temsilci_kodu <> '') AND (CARI_HESAPLAR.cari_RECno NOT IN (SELECT     CUSTOMER_ID FROM          MERCHANT_ROUTE WHERE      (WEEK_NO = 1) AND (MERCHANT_ROUTE.MERCHANT_ID=MERCHANT.ID) GROUP BY CUSTOMER_ID)) ");
            return sb.ToString();
        }
        public string EvrakListesi(bool tumu)
        {
            StringBuilder sb = new StringBuilder();
            sb.Append(" exec sp_executesql N' ");
            if (tumu)
                sb.Append(" select top 100 percent ");
            else
                sb.Append(" select top 100 ");

            sb.Append(" case when INVOICE_HEADER.DOCUMENT_TYPE =21 then ''Satış Faturası'' when INVOICE_HEADER.DOCUMENT_TYPE =10 then ''Alınan Sipariş'' when INVOICE_HEADER.DOCUMENT_TYPE =30 then ''Tahsilat'' else '''' end AS [Evrak Cinsi], ");
            sb.Append(" INVOICE_HEADER.DOCUMENT_DATE AS [Belge Tarihi],INVOICE_HEADER.INVOICE_SERIES AS [Belge Seri],INVOICE_HEADER.INVOICE_NUMBER AS [Belge Sıra], CARI_HESAPLAR.cari_kod AS [Cari Kodu],CARI_HESAPLAR.cari_unvan1 AS [Cari 1.Ünvanı], CARI_HESAPLAR.cari_unvan2 AS [Cari 2.Ünvanı], DEVICE_DEFINITIONS.ID AS [Terminal No], DEVICE_DEFINITIONS.DESCRIPTION AS [Terminal Bilgisi], INVOICE_HEADER.GENERAL_TOTAL AS Tutar, INVOICE_HEADER.SAVED_FLAG AS Kaydedildi,INVOICE_HEADER.ID,INVOICE_HEADER.DESCRIPTION AS [Bilgi] ");
            sb.Append(" FROM  INVOICE_HEADER INNER JOIN DEVICE_DEFINITIONS ON INVOICE_HEADER.TERMINAL_ID = DEVICE_DEFINITIONS.ID INNER JOIN CARI_HESAPLAR ON INVOICE_HEADER.CUSTOMER_CODE = CARI_HESAPLAR.cari_kod ");
            sb.Append(" ORDER BY [Belge Tarihi] DESC '");
            return sb.ToString();
        }
        public string UrunPromosyonListesi()
        {
            StringBuilder sb = new StringBuilder();
            sb.Append(" SELECT     t2.NAME AS [Promosyon Tanımı], t3.cari_unvan1 AS [Cari Ünvanı], STOKLAR_1.sto_isim AS [Stok Adı], t3.cari_kod, STOKLAR_1.sto_kod, \r\n");
            sb.Append(" (SELECT sto_kod FROM STOKLAR WHERE (sto_RECno = t1.PRM_PRODUCT_ID)) AS PrmStok, t1.PROMOTION_ID, t1.PRODUCT_ID, t1.PRM_PRODUCT_ID, t1.CUSTOMER_ID \r\n");
            sb.Append(" FROM         PRODUCT_PROMOTION AS t1 INNER JOIN STOKLAR AS STOKLAR_1 ON t1.PRODUCT_ID = STOKLAR_1.sto_RECno INNER JOIN PROMOTION_HEADER AS t2 ON t1.PROMOTION_ID = t2.CODE LEFT OUTER JOIN CARI_HESAPLAR AS t3 ON t1.CUSTOMER_ID = t3.cari_RECno  \r\n");
            return sb.ToString();
        }
        public DataTable ListeLoadData(ListeTipleri tip, string filtre)
        {
            string sqlstring = string.Empty;
            switch (tip)
            {
                case ListeTipleri.CariKodu:
                    sqlstring = "SELECT     cari_RECno as ID ,cari_kod AS [Cari Kodu], cari_unvan1 AS [Cari Ünvanı 1], cari_unvan2 AS [Cari Ünvanı 2]  FROM         CARI_HESAPLAR  WHERE     (cari_kod LIKE @kod)";
                    break;
                case ListeTipleri.CariAdi:
                    sqlstring = "SELECT     cari_RECno as ID ,cari_kod AS [Cari Kodu], cari_unvan1 AS [Cari Ünvanı 1], cari_unvan2 AS [Cari Ünvanı 2]  FROM         CARI_HESAPLAR  WHERE     (cari_unvan1 LIKE @kod)";
                    break;
                case ListeTipleri.StokKodu:
                    sqlstring = "SELECT     sto_RECno as ID ,sto_kod AS [Stok Kodu], sto_isim AS [Stok Adı]  FROM         STOKLAR  WHERE     (sto_kod like @kod)";
                    break;
                case ListeTipleri.StokAdi:
                    sqlstring = "SELECT     sto_RECno as ID ,sto_kod AS [Stok Kodu], sto_isim AS [Stok Adı]  FROM         STOKLAR  WHERE     (sto_isim like @kod)";
                    break;
                case ListeTipleri.Barkod:
                    sqlstring = "";
                    break;
                case ListeTipleri.Terminal:
                    sqlstring = "SELECT     ID AS [Terminal No], DESCRIPTION AS [Terminal Tanımı],DEVICE_CODE, LICENCE_CODE FROM         DEVICE_DEFINITIONS";
                    break;
                default:
                    sqlstring = "";
                    break;
            }
            SqlParameter prm = new SqlParameter("@kod", SqlDbType.VarChar);
            prm.Value = '%' + filtre + '%';
            return DataLayer.GetLayer.FillData(sqlstring, prm);
        }
        public string CariPromosyonListesi()
        {
            StringBuilder sb = new StringBuilder();
            sb.Append(" SELECT     CARI_HESAPLAR.cari_kod AS [Cari Kodu], CARI_HESAPLAR.cari_unvan1 AS [Cari Ünvanı], PROMOTION_HEADER.CODE AS [Promosyon Kodu], PROMOTION_HEADER.NAME AS [Promosyon Tanımı],CARI_HESAPLAR.cari_RECno,CUSTOMER_PROMOTION.PROMOTION_ID ");
            sb.Append(" FROM         CUSTOMER_PROMOTION INNER JOIN PROMOTION_HEADER ON CUSTOMER_PROMOTION.PROMOTION_ID = PROMOTION_HEADER.CODE INNER JOIN CARI_HESAPLAR ON CUSTOMER_PROMOTION.CUSTOMER_ID = CARI_HESAPLAR.cari_RECno ");
            return sb.ToString();
        }

        public string DepoSevkEkle(int tip, int cins, int normal_iade, int evrak_tip, DateTime evrak_tarih, string seri, int sira, int satir, string stok_kod, string cari_kod, decimal miktar, string giris_depo, string cikis_depo, int odeme, string plasiyer, string srmerkez, string kullanici, decimal yekun, decimal isk1tutar, decimal isk2tutar, decimal isk3tutar, decimal isk4tutar, decimal isk5tutar, int kdv, string ref_rec, string ref_dbc, decimal fiyat, string belge_no, string firma_no, string sube_no, bool sonlandir)
        {
            return this.SharEkle(tip, cins, normal_iade, evrak_tip, evrak_tarih, seri, sira, satir, stok_kod, cari_kod, miktar, giris_depo, cikis_depo, odeme, plasiyer, srmerkez, kullanici, yekun, isk1tutar, isk2tutar, isk3tutar, isk4tutar, isk5tutar, kdv, ref_rec, ref_dbc, fiyat, belge_no, firma_no, sube_no, 1, 0);
        }
    }
}
